from typing import List, Optional
from pydantic import BaseModel, ConfigDict, field_validator
from datetime import datetime

# VoteOption 模型
class VoteOptionBase(BaseModel):
    content: str
class UserVoteRequest(BaseModel):
    options: int  # 单选值
    model_config = ConfigDict(from_attributes=True)
class VoteOption(BaseModel):
    id: int
    content: str
    vote_count: int = 0  # Set default value
    vote_id: int

    model_config = ConfigDict(from_attributes=True)



# Vote 模型
class VoteBase(BaseModel):
    question: str
    question_type: str  # "single_choice" or "multiple_choice"

class VoteCreate(VoteBase):
    options: List[str]  # 选项内容列表

class VoteUpdate(VoteBase):
    question: Optional[str] = None
    question_type: Optional[str] = None

class Vote(VoteBase):
    id: int
    created_at: datetime
    options: List[VoteOption]

    model_config = ConfigDict(from_attributes=True)